package com.itheima.controller;

import com.itheima.pojo.Emp;
import com.itheima.pojo.LoginInfo;
import com.itheima.service.EmpService;
import com.itheima.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

//@RestController
public class LoginController2 {
    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody Emp emp) {
        if (emp == null || !StringUtils.hasText(emp.getUsername()) || !StringUtils.hasText(emp.getPassword())){
            return Result.error("用户名或密码为空");
        }
        LoginInfo loginInfo = empService.login(emp);
        return Result.success(loginInfo);
    }
}
